<template>
  <div>
    <van-nav-bar
      title="意见反馈"
      left-text="返回"
      left-arrow
      @click-left="onClickLeft"
      bind:click-left="onClickLeft"
    />
    <el-form ref="form" :model="form">
      <el-form-item>
        <el-input type="textarea" v-model="form.opinion" placeholder="请留下您的宝贵意见或建议"></el-input>
      </el-form-item>
        <el-upload
          class="avatar-uploader"
          action="http://113.44.137.179:6001/user/feedback/fileUpload"
          name="file"
          :show-file-list="false"
          :on-success="handleAvatarSuccess"
          :before-upload="beforeAvatarUpload">
          <img v-if="imageUrl" :src="imageUrl" class="avatar">
          <i v-else class="el-icon-plus avatar-uploader-icon"></i>
        </el-upload>
      <el-input v-model="form.phone" placeholder="联系方式">
        <template slot="prepend">+86</template>
      </el-input>
      <el-button type="primary" @click="submitFeedback" class="b1">提交</el-button>
    </el-form>
  </div>
</template>

<script>
import axios from "axios";
import {Toast} from "vant";

export default {
  data() {
    return {
      imageUrl: '',
      form:{
        image:'',
      },
    }
  },
  methods: {
    handleAvatarSuccess(res, file) {
      this.imageUrl = res;
    },
    beforeAvatarUpload(file) {
      return null;
    },
    submitFeedback() {
      // 这里可以添加提交反馈的逻辑，例如发送AJAX请求
      this.form.image=this.imageUrl;
      axios.post(`/user/feedback/add`,this.form).then(res=>{
        if (res.data.code ==1){
          this.$message.success('提交成功');
          this.$router.push({path:'/myShow'});
        }else {
          this.$message.error('提交失败');
        }
      })
    },
    onClickLeft() {
      Toast('返回');
      //返回上一个页面
      this.$router.go(-1);
    },
  }
}
</script>
<style>
textarea {
  height: 200px;
}
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.avatar-uploader {
  text-align: left;
}

.avatar-uploader .el-upload:hover {
  border-color: #409EFF;
}

.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 120px;
  height: 120px;
  line-height: 120px;
  text-align: center;
  border: 1px solid #d9d9d9;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
.b1 {
  width: 200px;
}
</style>
